
function bytesToSize(bytes, precision)
{  
    var kilobyte = 1024;
    var megabyte = kilobyte * 1024;
    var gigabyte = megabyte * 1024;
    var terabyte = gigabyte * 1024;
   
    if ((bytes >= 0) && (bytes < kilobyte)) {
        return bytes + ' B';
 
    } else if ((bytes >= kilobyte) && (bytes < megabyte)) {
        return (bytes / kilobyte).toFixed(precision) + ' KB';
 
    } else if ((bytes >= megabyte) && (bytes < gigabyte)) {
        return (bytes / megabyte).toFixed(precision) + ' MB';
 
    } else if ((bytes >= gigabyte) && (bytes < terabyte)) {
        return (bytes / gigabyte).toFixed(precision) + ' GB';
 
    } else if (bytes >= terabyte) {
        return (bytes / terabyte).toFixed(precision) + ' TB';
 
    } else {
        return bytes + ' B';
    }
}
function addformupload(config)
{

    //console.log(config);
    $("#addform").append('<div id="feature'+rowdiv+'" class="itPlg addUlPlg featureclass">'+dataform['upload']+"</div>");
    var rownow=rowdiv;
    
    
  $('#feature'+rownow+' .areafile').iuploader({
         'link':serviceinfo+'iuploadfile',
         'accept':config.accept,
         'group':rownow,
         'type':config.allow,
         'onStartUpload':function(setting){
         $('#feature'+rownow+' .ico2.icoCrtGrn').hide();
         $('#feature'+rownow+' .btnIco.upAddIco').hide();
         
         var bytename=bytesToSize(setting['size'],2);
         $('#feature'+rownow+' .fileSize').html(bytename);
         $('#feature'+rownow+' .fileName').html(setting['fileold']);
         },
         'load':$('#feature'+rownow+' .ulPg.clTxtW.fs09'),
         'finish':$('#feature'+rownow+' .ico2.icoCrtGrn'),
         'isimg':false,
         'onUploadFinish':function(filename,filelink,setting){
         
          $("#fileid-"+setting.id).val(setting.fileid);
          $("#fileold-"+setting.id).val(setting.fileold);
         
          $('#feature'+rownow+' .fileName').html('<a href="'+filelink+'" target="'+filelink+'">'+setting.fileold+'</a>');
         
         
         

         //alert(filename);
         }
   });
   $('#feature'+rownow+' .deletebutton').click(function() {
   $('#feature'+rownow+' .fileName').html('');
   $('#feature'+rownow+' .fileSize').html('');
   $('#feature'+rownow+' input[name="fileold[]"]').val('');
   $('#feature'+rownow+' input[name="fileid[]"]').val('');
   $('#feature'+rownow+' input[name="filelink[]"]').val('');
   $('#feature'+rownow+' .btnIco.upAddIco').show();
   $('#feature'+rownow+' .ico2.icoCrtGrn').hide();
   
   });
   
   $('#feature'+rownow+' .deleterowbutton').click(function(){
   
    $('#feature'+rownow).remove();
    
   });
   
   

    
    
    
    
    rowdiv++;

}

function saveformupload(id,plugid)
{
var obj={};
if($("#"+id+' input[name="fileid[]"]').val()!="")
{
obj={plugid:plugid,fileid:$("#"+id+' input[name="fileid[]"]').val(),detail:$("#"+id+' textarea[name="detail[]"]').val()};
}

return obj;

}
function getformupload(dataplugin)
{
var code="";
if(dataplugin.file.filename)
{
code = '<div class="ldIt wrpDlLd clBg4">\n';
code += '<h2 class="clTxt2 fs04">Download Menu</h2>\n';
code += '<div class="wrpInDlLd">\n';
code += '<div class="btnIco dlLd">\n';
code += '<abbr title="Download">\n';
code += '<span class="ico2 icoDlLd"></span>\n';
code += '</abbr>\n';
code += '</div>\n';
code += '<a href="'+dataplugin.file.newpath+'" target="_blank">\n';
code += '<div class="desFileDlLd">\n';
code += '<span class="fileName">'+dataplugin.file.filename+'</span><br>\n';
code += '<span class="fileSize">'+dataplugin.file.size+' kb</span>\n';
code += '</div>\n';
code += '</a>\n';
code += '</div>\n';
code += '<div class="desDlLd">\n';
code += '<p>'+dataplugin.detail+'</p>\n';
code += '</div>\n';
code += '</div>';
}


return code;

}
function editformupload(config,datarow)
{
    if(datarow.fileid!="0")
    {
     addformupload(config);
     var rownow= rowdiv-1;
      
       $('#feature'+rownow+' input[name="fileid[]"]').val(datarow.fileid);
       $('#feature'+rownow+' .fileName').html('<a href="'+datarow.file.newpath+'" target="'+datarow.file.newpath+'">'+datarow.file.filename+'</a>');
       $('#feature'+rownow+' .btnIco.upAddIco').hide();
       $('#feature'+rownow+' .ico2.icoCrtGrn').show();
       $('#feature'+rownow+' input[name="detail[]"]').val(datarow.detail);
    }
       
}